package com.fenqing.leetcode.code.sword_refers_offer_ii;

import com.fenqing.annotations.Execute;
import com.fenqing.core.Topic;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author fenqing
 */
public class Topic079 extends Topic {
    /**
     * 构造器
     *
     * @param input         输入
     */
    public Topic079(String input) {
        super(input);
    }


    @Execute
    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> result = new ArrayList<>();
        subsets(nums, 0, result, new ArrayList<>());
        return result;
    }

    private void subsets(int[] nums, int index, List<List<Integer>> list, List<Integer> temp){
        if(index > nums.length){
            return;
        }
        int i = index - 1;
        if (i >= 0) {
            temp.add(nums[i]);
        }
        list.add(temp);
        for (int j = index; j < nums.length; j++) {
            subsets(nums, j + 1, list, new ArrayList<>(temp));
        }

    }

    public static void main(String[] args) {
        List<List<Integer>> run = new Topic079("[1,2,3]").run();
        run.forEach(System.out::println);
    }
}
